<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script>
            /* var a = 1
        function fn(){
            a = 2
            console.log(a) // 2
        }
        fn()
        console.log(a) // 2 */

            // 变量和函数的提升同样适用于函数作用域

            /*  var a = 1
        function fn(){
            console.log(a) //undefined
            var a = 2
            console.log(a) // 2
        }
        fn()
        console.log(a) // 1 */

            // 定义形参就相当于在函数中声明了对应的变量，但是没有赋值
            /* var a = 1
        function fn(a){
            console.log(a) //undefined
            a = 2
            console.log(a) // 2
        }
        fn()
        console.log(a) // 1 */

            /* var a = 1
        function fn(a){
            console.log(a) //10
            a = 2
            console.log(a) // 2
        }
        fn(10)
        console.log(a) // 1
 */

            /* var a = 1
        function fn(a){
            console.log(a) //1
            a = 2
            console.log(a) // 2
        }
        fn(a)
        console.log(a) // 1 */

            console.log(a)  // 2

            var a = 1

            console.log(a) // 1

            function a() {
                alert(2)
            }

            console.log(a) // 1

            var a = 3

            console.log(a) // 3

            var a = function () {
                alert(4)
            }

            console.log(a) // 4

            var a

            console.log(a) // 4
        </script>
    </head>
    <body></body>
</html>
